package org.fit.pdfdom;

import cn.arktao.lessonplanhtml.Utils.Utils;
import lombok.extern.slf4j.Slf4j;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

@Slf4j
public class D {
    private static Boolean isFirst = true;
    public static void saveImage(BufferedImage img) throws IOException {
        String savePath = "D://tempOutImg//";
        File dir = new File(savePath);
        if (dir.exists() && isFirst){
            isFirst = false;
            Utils.delDir(dir);
        }
        if(!dir.mkdirs()){
            log.error("Mkdir error");
        }
        File imageFile=new File(savePath, Math.random() * 1000 + ".png");
        log.warn("Saving image [{}]", imageFile.getAbsolutePath());
        ImageIO.write(img, "png", imageFile);

    }
}
